function [all_p_l , all_dates_b, all_dates_s] = compute_PL...
    (trades, all_prices_clo, all_prices_hi, all_prices_lo,...
    all_dates_ret, trade_type, tran_cost)

all_p_l = [];
all_dates_b = [];
all_dates_s = [];
idx = 1:2:size(trades,1)-1;

switch trade_type
    case 'normal'
        for i = 1:size(idx,2)
            price_b = all_prices_clo(2*trades(idx(i),2) - 1);
            price_s = all_prices_clo(2*trades(idx(i)+1,2) - 1);
            
            price_b = price_b / (1 - tran_cost);
            price_s = price_s * (1 - tran_cost);
            
            dates_b = all_dates_ret(2*trades(idx(i),2) - 1);
            dates_s = all_dates_ret(2*trades(idx(i)+1,2) - 1);
            
            p_l = (price_s - price_b)/price_b;
            
            all_p_l = [all_p_l ; p_l];
            all_dates_b = [all_dates_b ; dates_b];
            all_dates_s = [all_dates_s ; dates_s];
        end
    case 'worst'
        for i = 1:size(idx,2)
            price_b = all_prices_hi(2*trades(idx(i),2) - 1);
            price_s = all_prices_lo(2*trades(idx(i)+1,2) - 1);
            
            price_b = price_b / (1 - tran_cost);
            price_s = price_s * (1 - tran_cost);
            
            dates_b = all_dates_ret(2*trades(idx(i),2) - 1);
            dates_s = all_dates_ret(2*trades(idx(i)+1,2) - 1);
            
            p_l = (price_s - price_b)/price_b;
            
            all_p_l = [all_p_l ; p_l];
            all_dates_b = [all_dates_b ; dates_b];
            all_dates_s = [all_dates_s ; dates_s];
        end
end
end
   
        
